package com.yjt.fresh.activity;

import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.BaseResultEntity;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.http.HttpManager;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.listener.HttpOnNextListener;
import com.yjt.fresh.R;
import com.yjt.fresh.api.ApiRechargeByCard;
import com.yjt.fresh.base.BaseSimpleActivity;
import com.yjt.fresh.utils.PreferenceManager;
import com.yjt.fresh.widget.CustomToastResult;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;

public class AtyRechargeByCard extends BaseSimpleActivity {
    @BindView(R.id.rlBack)
    RelativeLayout mRlBack;
    @BindView(R.id.edtAppAtyRechargeByCard)
    EditText mEdt;
    @BindView(R.id.btnAppAtyRechargeByCardSubmit)
    Button mBtnSubmit;

    @Override
    protected int getContentView() {
        return R.layout.app_aty_recharge_by_card;
    }

    @Override
    protected void initViews() {
        ButterKnife.bind(this);
    }

    @Override
    protected void initEvent() {
        mBtnSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (TextUtils.isEmpty(mEdt.getText().toString().trim())) {
                    Toast.makeText(mContext, "请输入卡密", Toast.LENGTH_SHORT).show();
                } else {
                    recharge();
                }
            }
        });
    }

    private void recharge() {
        ApiRechargeByCard apiRechargeByCard = new ApiRechargeByCard(new HttpOnNextListener<BaseResultEntity>() {
            @Override
            public void onNext(BaseResultEntity baseResultEntity) {
                CustomToastResult.show("充值成功");
                finish();
            }

            @Override
            public void failed(String massage) {
                super.failed(massage);
                CustomToastResult.showWithIvID("卡密无效", Toast.LENGTH_SHORT, R.mipmap.b1_nva_ic_01);
            }

            @Override
            public void onReLogin() {

            }
        }, mContext, true, false, false);

        Map<String, Object> map = new HashMap<>();
        map.put("SESSION_ID", PreferenceManager.getInstance().getUserInfo().getSESSION_ID());
        map.put("PASSWORD", mEdt.getText().toString().trim());
        apiRechargeByCard.setMap(map);
        HttpManager.getInstance().doHttpDeal(apiRechargeByCard);
    }

}
